package com.websocket.exception.service;

import com.websocket.service.WebSocketTemplate;
import org.java_websocket.WebSocket;
import org.springframework.context.ApplicationContext;

public class ExceptionDispatch {

    private final ExceptionMapping exceptionMapping;
    private final ExceptionAdaptor exceptionAdaptor;

    public ExceptionDispatch(ApplicationContext applicationContext, WebSocketTemplate template) {
        this.exceptionMapping = new ExceptionMapping(applicationContext);
        this.exceptionAdaptor = new ExceptionAdaptor(template);
    }

    public void doDispatch(Exception e, WebSocket conn) {
        ExceptionExecution handler = exceptionMapping.getHandler(e);
        exceptionAdaptor.handle(handler, e, conn);
    }
}
